/**
*      author: Y_Yao
*      created: 2024-11-27 11:01:34
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int mod = 80112002;
const int N = 5e3 + 7;
int adj[N][N];
vector<int> dp(N,1);
int n,m;

void solve()
{
    cin >> n >> m;
    for(int i = 1;i <= m;i++)
    {
        int a,b;
        cin >> a >> b;
        adj[b][a] = 1;//b吃a
    }

    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        for(int j = i - 1;j > 0;j--)
        {
            if(adj[i][j] && dp[i] < dp[j] + 1)
            {
                dp[i] = (dp[j] + 1) % mod;
            }
        }
        ans = max(ans,dp[i]) % mod;
    }

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}